<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>活动抽奖</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <style>
        :root {
            --bg0: #0a0a16;
            --bg1: #160b2e;
            --neonC: #ff2a6d;
            --neonM: #05d9e8;
            --glass: rgba(255,255,255,.05);
            --radius: 12px;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Orbitron', sans-serif;
        }

        body {
            min-height: 100vh;
            background: linear-gradient(135deg,var(--bg0),var(--bg1));
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            overflow-x: hidden;
        }

        .container {
            max-width: 800px;
            width: 100%;
            text-align: center;
            animation: fadeIn .6s;
            position: relative;
            z-index: 2;
        }

        h1 {
            font-size: 3rem;
            letter-spacing: 3px;
            margin-bottom: .5em;
            text-transform: uppercase;
            color: #fff;
            text-shadow: 0 0 10px var(--neonM), 0 0 20px var(--neonM), 0 0 30px var(--neonM);
        }

        .cyber-border {
            border: 2px solid var(--neonC);
            box-shadow: 0 0 15px var(--neonC), inset 0 0 15px var(--neonC);
            position: relative;
            padding: 5px;
        }

        .cyber-border::before, .cyber-border::after {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            border: 2px solid var(--neonC);
        }

        .cyber-border::before {
            top: -5px;
            left: -5px;
            border-right: none;
            border-bottom: none;
        }

        .cyber-border::after {
            bottom: -5px;
            right: -5px;
            border-left: none;
            border-top: none;
        }

        .grid-container {
            display: grid;
            grid-template-columns: repeat(3,1fr);
            gap: 15px;
            max-width: 480px;
            margin: 30px auto;
            padding: 25px;
            background: rgba(0,0,0,.5);
            border-radius: var(--radius);
            backdrop-filter: blur(8px);
            position: relative;
        }

        .grid-item {
            aspect-ratio: 1/1;
            background: rgba(0,0,0,.7);
            border: 1px solid var(--neonC);
            border-radius: var(--radius);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            transition: .3s;
            position: relative;
            overflow: hidden;
            box-shadow: 0 0 10px var(--neonC);
        }

        .grid-item.active {
            background: rgba(255,42,109,.3);
            transform: scale(1.05);
            box-shadow: 0 0 20px var(--neonC);
            z-index: 2;
        }

        .grid-item.win {
            animation: cyberPulse 1s infinite;
        }

        @keyframes cyberPulse {
            0%,100% {
                box-shadow: 0 0 10px var(--neonC), 0 0 20px var(--neonM);
            }
            50% {
                box-shadow: 0 0 30px var(--neonC), 0 0 50px var(--neonM);
                transform: scale(1.08);
            }
        }

        .prize-icon {
            font-size: 2.5rem;
            margin-bottom: 8px;
            filter: drop-shadow(0 0 5px var(--neonM));
        }

        .prize-name {
            font-size: 0.9rem;
            font-weight: 600;
            color: var(--neonM);
        }

        .prize-value {
            font-size: .7rem;
            opacity: .8;
            color: #fff;
        }

        .button-container {
            display: flex;
            justify-content: center;
            gap: 15px;
            flex-wrap: wrap;
            margin: 25px 0;
        }

        .cyber-btn {
            padding: 12px 28px;
            font-size: 1rem;
            font-weight: 700;
            border: none;
            border-radius: 0;
            cursor: pointer;
            transition: .3s;
            color: #fff;
            position: relative;
            overflow: hidden;
            background: transparent;
            text-transform: uppercase;
            letter-spacing: 2px;
        }

        .cyber-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(45deg, transparent, rgba(255,42,109,.3), transparent);
            transform: translateX(-100%);
            transition: .5s;
        }

        .cyber-btn:hover::before {
            transform: translateX(100%);
        }

        .btn-start {
            border: 2px solid #00ff9d;
            box-shadow: 0 0 10px #00ff9d, inset 0 0 10px #00ff9d;
        }

        .btn-stop {
            border: 2px solid #ff2a6d;
            box-shadow: 0 0 10px #ff2a6d, inset 0 0 10px #ff2a6d;
        }

        .btn-reset {
            border: 2px solid #05d9e8;
            box-shadow: 0 0 10px #05d9e8, inset 0 0 10px #05d9e8;
        }

        .cyber-btn:hover:not(:disabled) {
            transform: translateY(-5px);
        }

        .cyber-btn:disabled {
            opacity: .4;
            cursor: not-allowed;
            transform: none;
        }

        .result-container, .speed-control, .history {
            background: rgba(0,0,0,.5);
            border: 1px solid var(--neonM);
            border-radius: var(--radius);
            padding: 20px;
            margin: 20px auto;
            max-width: 480px;
            backdrop-filter: blur(8px);
            box-shadow: 0 0 15px var(--neonM);
        }

        .result-title {
            color: var(--neonM);
            font-size: 1.4rem;
            margin-bottom: 10px;
            text-transform: uppercase;
            letter-spacing: 2px;
        }

        .result-content {
            padding: 20px;
            min-height: 150px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }

        .result-icon {
            font-size: 3rem;
            margin-bottom: 10px;
            filter: drop-shadow(0 0 5px var(--neonM));
        }

        .result-text {
            font-size: 1.1rem;
        }

        .result-name {
            font-weight: bold;
            color: var(--neonC);
            margin-bottom: 5px;
        }

        .result-value {
            font-size: 0.9rem;
            opacity: 0.8;
        }

        .scan-line {
            height: 2px;
            background: linear-gradient(90deg, transparent, var(--neonM), transparent);
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            animation: scan 2s linear infinite;
        }

        @keyframes scan {
            0% { top: 0; }
            100% { top: 100%; }
        }

        .slider-container {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-top: 15px;
        }

        input[type=range] {
            flex: 1;
            -webkit-appearance: none;
            height: 6px;
            border-radius: 3px;
            background: rgba(255,255,255,0.1);
            outline: none;
        }

        input[type=range]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: var(--neonM);
            cursor: pointer;
            box-shadow: 0 0 10px var(--neonM);
        }

        .history-list {
            display: flex;
            justify-content: center;
            gap: 12px;
            overflow-x: auto;
            padding: 10px 0;
        }

        .history-item {
            flex: 0 0 140px;
            background: rgba(0,0,0,0.3);
            border: 1px solid var(--neonM);
            border-radius: var(--radius);
            padding: 12px;
            display: flex;
            flex-direction: column;
            align-items: center;
            font-size: .85rem;
            min-width: 120px;
        }

        .history-icon {
            font-size: 1.8rem;
            margin-bottom: 6px;
            filter: drop-shadow(0 0 5px var(--neonM));
        }

        .history-name {
            font-weight: 600;
            margin-bottom: 4px;
            color: var(--neonC);
        }

        .history-time {
            opacity: .6;
            font-size: .75rem;
        }

        .cyber-bg {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
            opacity: 0.3;
            pointer-events: none;
        }

        .cyber-grid {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-image: 
                linear-gradient(rgba(5, 217, 232, 0.1) 1px, transparent 1px),
                linear-gradient(90deg, rgba(5, 217, 232, 0.1) 1px, transparent 1px);
            background-size: 30px 30px;
        }

        .cyber-glitch {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            background: var(--neonM);
            mix-blend-mode: overlay;
            animation: glitch 10s infinite alternate;
        }

        @keyframes glitch {
            0%, 100% { opacity: 0; transform: translate(0); }
            5% { opacity: 0.1; transform: translate(-5px, 5px); }
            10% { opacity: 0; transform: translate(0); }
            96% { opacity: 0; transform: translate(0); }
            98% { opacity: 0.2; transform: translate(10px, -10px); }
        }

        .confetti {
            position: fixed;
            width: 8px;
            height: 8px;
            top: -10px;
            border-radius: 50%;
            animation: fall 3s linear forwards;
            z-index: 1000;
        }

        @keyframes fall {
            to {
                transform: translateY(110vh) rotate(720deg);
                opacity: 0;
            }
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap" rel="stylesheet">
</head>
<body>
    <div class="cyber-bg">
        <div class="cyber-grid"></div>
        <div class="cyber-glitch"></div>
    </div>
    
    <div class="container">
        <h1>活动抽奖</h1>

        <!-- 速度滑条 -->
        <div class="speed-control cyber-border">
            <h3>速度控制模块</h3>
            <div class="slider-container">
                <input type="range" id="speedSlider" min="1" max="10" value="5">
                <span id="speedValue">5</span>
            </div>
        </div>

        <!-- 九宫格 -->
        <div class="grid-container cyber-border">
            <div class="scan-line"></div>
            <div class="grid-item"><div class="prize-icon">🎮</div><div class="prize-name">游戏主机</div><div class="prize-value">¥2999</div></div>
            <div class="grid-item"><div class="prize-icon">📱</div><div class="prize-name">智能手机</div><div class="prize-value">¥3999</div></div>
            <div class="grid-item"><div class="prize-icon">💻</div><div class="prize-name">笔记本电脑</div><div class="prize-value">¥5999</div></div>
            <div class="grid-item"><div class="prize-icon">🎧</div><div class="prize-name">无线耳机</div><div class="prize-value">¥899</div></div>
            <div class="grid-item"><div class="prize-icon">⌚</div><div class="prize-name">智能手表</div><div class="prize-value">¥1299</div></div>
            <div class="grid-item"><div class="prize-icon">🎁</div><div class="prize-name">神秘礼盒</div><div class="prize-value">¥1999</div></div>
            <div class="grid-item"><div class="prize-icon">🎫</div><div class="prize-name">优惠券</div><div class="prize-value">满1000减200</div></div>
            <div class="grid-item"><div class="prize-icon">🧧</div><div class="prize-name">现金红包</div><div class="prize-value">¥888</div></div>
            <div class="grid-item"><div class="prize-icon">🎨</div><div class="prize-name">画板套装</div><div class="prize-value">¥599</div></div>
        </div>

        <!-- 按钮 -->
        <div class="button-container">
            <button class="cyber-btn btn-start" id="startButton">启动</button>
            <button class="cyber-btn btn-stop" id="stopButton" disabled>停止</button>
            <button class="cyber-btn btn-reset" id="resetButton">重置</button>
        </div>

        <!-- 结果 -->
        <div class="result-container cyber-border">
            <div class="scan-line"></div>
            <div class="result-title">抽奖结果</div>
            <div class="result-content" id="resultContent">
                <div class="result-icon">🎰</div>
                <div class="result-text">等待启动...</div>
            </div>
        </div>

        <!-- 抽奖记录 -->
        <div class="history cyber-border">
            <h2>抽奖记录</h2>
            <div class="history-list" id="historyList">
                <div class="history-item">
                    <div class="history-icon">📝</div>
                    <div class="history-name">暂无记录</div>
                    <div class="history-time">--:--:--</div>
                </div>
            </div>
        </div>
    </div>

    <script>
        /* === 基本数据 === */
        const prizes = [...document.querySelectorAll('.grid-item')].map(el => ({
            name: el.querySelector('.prize-name').textContent,
            value: el.querySelector('.prize-value').textContent,
            icon: el.querySelector('.prize-icon').textContent
        }));
        const gridItems = document.querySelectorAll('.grid-item');
        const startBtn = document.getElementById('startButton');
        const stopBtn = document.getElementById('stopButton');
        const resetBtn = document.getElementById('resetButton');
        const resultBox = document.getElementById('resultContent');
        const historyBox = document.getElementById('historyList');
        const speedSlider = document.getElementById('speedSlider');
        const speedValue = document.getElementById('speedValue');

        let isSpin = false, current = 0, win = -1, timer = null;
        let base = 50, factor = 5;
        
        speedSlider.addEventListener('input', e => { 
            factor = +e.target.value; 
            speedValue.textContent = factor; 
        });

        const speed = () => Math.max(10, base / factor);

        /* === 功能函数 === */
        function reset() {
            clearTimeout(timer); 
            isSpin = false; 
            current = 0; 
            win = -1;
            gridItems.forEach(el => el.classList.remove('active', 'win'));
            resultBox.innerHTML = '<div class="result-icon">🎰</div><div class="result-text">等待启动...</div>';
            startBtn.disabled = false; 
            stopBtn.disabled = true;
        }
        
        function start() {
            if (isSpin) return;
            reset(); 
            isSpin = true; 
            startBtn.disabled = true; 
            stopBtn.disabled = false;
            win = Math.floor(Math.random() * 9);
            resultBox.innerHTML = '<div class="result-icon">🎡</div><div class="result-text">抽奖进行中...</div>';
            run();
        }
        
        function run() {
            gridItems.forEach(el => el.classList.remove('active'));
            gridItems[current].classList.add('active');
            current = (current + 1) % 9;
            if (current === win && Math.random() > .7) { 
                setTimeout(end, 100); 
                return; 
            }
            timer = setTimeout(run, speed());
        }
        
        function stopLottery() {
            if (!isSpin) return;
            clearTimeout(timer); 
            isSpin = false;
            if (win < 0) win = Math.floor(Math.random() * 9);
            gridItems.forEach(el => el.classList.remove('active'));
            gridItems[win].classList.add('active', 'win');
            showResult();
            startBtn.disabled = false; 
            stopBtn.disabled = true;
        }
        
        function end() { 
            stopLottery(); 
        }
        
        function showResult() {
            const p = prizes[win];
            resultBox.innerHTML = `
                <div class="result-icon">${p.icon}</div>
                <div class="result-text">
                    <div class="result-name">${p.name}</div>
                    <div class="result-value">${p.value}</div>
                </div>`;
            confetti(); 
            addHistory(p);
        }
        
        function confetti() {
            const colors = ['#00f9ff', '#ff00a0', '#ffffff', '#00ffa2', '#ffea00'];
            for (let i = 0; i < 150; i++) {
                const c = document.createElement('div');
                c.className = 'confetti';
                c.style.left = Math.random() * 100 + 'vw';
                c.style.background = colors[Math.floor(Math.random() * colors.length)];
                c.style.width = c.style.height = Math.random() * 8 + 4 + 'px';
                document.body.appendChild(c);
                setTimeout(() => c.remove(), 3000);
            }
        }
        
        let history = [];
        function addHistory(p) {
            const t = new Date();
            history.unshift({ ...p, time: t.toLocaleTimeString() });
            if (history.length > 5) history.pop();
            updateHistory();
        }
        
        function updateHistory() {
            if (!history.length) {
                historyBox.innerHTML = `
                    <div class="history-item">
                        <div class="history-icon">📝</div>
                        <div class="history-name">暂无记录</div>
                        <div class="history-time">--:--:--</div>
                    </div>`;
                return;
            }
            
            historyBox.innerHTML = '';
            history.forEach(h => {
                const d = document.createElement('div');
                d.className = 'history-item';
                d.innerHTML = `
                    <div class="history-icon">${h.icon}</div>
                    <div class="history-name">${h.name}</div>
                    <div class="history-time">${h.time}</div>`;
                historyBox.appendChild(d);
            });
        }

        /* === 事件 === */
        startBtn.addEventListener('click', start);
        stopBtn.addEventListener('click', stopLottery);
        resetBtn.addEventListener('click', reset);
        
        // 初始化
        reset(); 
        updateHistory();
    </script>
</body>
</html>